/*
* Copyright (c) 2025 Shenzhen Kaihong Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use std::path::PathBuf;

use anyhow::Context;
use clap::{Parser, ValueEnum};
use ohmw_codegen::msg_def::MsgDefMap;

#[derive(Debug, Parser)]
struct Args {
    /// The directory to read the message definitions from
    #[clap(short, long)]
    msgs_dir: PathBuf,
    /// The directory to output the generated code
    #[clap(short, long)]
    out_dir: PathBuf,
    /// The language to generate code for
    #[clap(short, long, default_value = "rust")]
    language: Language,
}

#[derive(Default, Debug, Clone, Copy, ValueEnum)]
enum Language {
    #[default]
    Rust,
    C,
    Cxx,
    Arkts,
    Napi,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let args = Args::parse();

    let msg_def_map = MsgDefMap::from_msgs_dir(args.msgs_dir).await
        .context("failed to scan message definitions")?;

    match args.language {
        Language::Rust => msg_def_map.gen_rust_crate(args.out_dir).await
            .context("failed to generate Rust code")?,
        Language::C => todo!(),
        Language::Cxx => msg_def_map.gen_cxx_project(args.out_dir).await
            .context("failed to generate C++ code")?,
        Language::Arkts => msg_def_map.gen_arkts_protos(args.out_dir).await
            .context("failed to generate ArkTS code")?,
        Language::Napi => msg_def_map.gen_napi_project(args.out_dir).await
            .context("failed to generate NAPI code")?,
    }
    Ok(())
}
